package com.yykj.common.util;

import com.yykj.common.constant.CommonConstant;
import org.springframework.util.StringUtils;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import static com.yykj.common.constant.CommonConstant.DEFAULT_PASSWORD;

/**
 * Created by chendg on 2020/9/8 0008.
 */
public class LocalStringUtil {

    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String encrypt(String str) {
        return MD5Util.md5Encode(CommonConstant.ENCRYPT_PREFIX + str);
    }

    public static String getDateString() {
        return DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now());
    }

    public static String getLikeString(String keyword) {
        return "%" + keyword + "%";
    }

    public static int getCurrentTimeInt(){
        long epochSecond = Instant.now().getEpochSecond();
        return (int) epochSecond;
    }


    public static Set<String> splitStrToSet(String str){
        Set<String> ret = new HashSet<>();
        if(!StringUtils.isEmpty(str)){
            String[] split = str.split(",");
            ret.addAll(Arrays.asList(split));
        }
        return ret;
    }

    public static synchronized String getOrderNum(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + LocalMathUtil.randomInt();
    }

}